//
//  NewsModel.m
//  ZzzzyManProject
//
//  Created by mac on 16/3/8.
//  Copyright © 2016年 ZzzzyMan@. All rights reserved.
//

#import "NewsModel.h"
#import <AVQuery.h>

@implementation NewsModel

//字典转模型
+ (instancetype)newsModelWithDict:(NSDictionary *)dict {
    NewsModel * model = [[NewsModel alloc] init];
    [model setValuesForKeysWithDictionary:dict];
    return model;
}

//忽略字段
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}

//获取数据的方法
+ (void)newsModelSuccessBlock:(void(^)(NSArray * array))SuccessBlock errorBlock:(void(^)(NSError * error))errorBlock {
    AVQuery *query = [AVQuery queryWithClassName:@"MarvelNews"];
    [query getObjectInBackgroundWithId:@"56de81da128fe1005acee195" block:^(AVObject *object, NSError *error) {
        
        NSDictionary * dict = (NSDictionary *)object;
        NSArray * tempArray = dict[@"news"];
        NSMutableArray * arrM = [[NSMutableArray alloc] initWithCapacity:tempArray.count];
        for (NSDictionary * tempDict in tempArray) {
            NewsModel * model = [NewsModel newsModelWithDict:tempDict];
            [arrM addObject:model];
        }
        
        if (object) {
            SuccessBlock(arrM.copy);
        }
        else if (error) {
            errorBlock(error);
        }
        
        
    }];
    
}

@end
